package com.example.flinkcourse.lesson1.transform;

import org.apache.flink.api.java.functions.KeySelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 自定义 KeySelector 转换函数
 * 用于数据聚合（按业务主键归类）
 */
public class MyKeySelector implements KeySelector<String, String> {
    private static final Logger LOG = LoggerFactory.getLogger(MyKeySelector.class);

    @Override
    public String getKey(String value) throws Exception {
        LOG.debug("Selecting key for record: {}", value);
        
        // 示例：使用字符串的第一个字符作为key
        String key = value.isEmpty() ? "EMPTY" : value.substring(0, 1);
        
        LOG.debug("Selected key: {}", key);
        return key;
    }
} 